import { getMusicLyric } from '@/request/api/item.js'
import { createStore } from 'vuex'
import { getPhoneLogin } from '@/request/api/home.js'
export default createStore({
  state: {
    playList: [{//播放列表添加默认值
      al: {
        id: 149878590,
        name: "你不是一个人",
        pic: 109951167790113440,
        picUrl: "https://p2.music.126.net/LYjbauJ0VQBrkHhsl-TM0Q==/109951167790113435.jpg",
        pic_str: "109951167790113435"
      },
      id: 1973067211,
      ar: [{
        name: "张信哲"
      }]
    }],
    playListIndex: 0,//默认下标为0
    isbtnShow: true,//暂停按钮的显示
    detailShow: false,//歌曲详情页的显示
    lyricList: {},
    currentTime: 0,
    duration: 0, //歌曲总时长
    isLogin: false,
  },
  getters: {
  },
  mutations: {
    updateisbtnShow: function (state, value) {
      state.isbtnShow = value
    },
    pushPlayList: function (state, value) {
      state.playList.push(value)
    },
    updatePlayList: function (state, value) {
      state.playList = value
    },
    updatePlayListIndex: function (state, value) {
      state.playListIndex = value
    },
    updateDetailShow: function (state) {
      state.detailShow = !state.detailShow
    },
    updateLyricList: function (state, value) {
      state.lyricList = value
    },
    updateCurrentTime: function (state, value) {
      state.currentTime = value
    },
    updateDuration: function (state, value) {
      state.duration = value
    },
    updateIsLogin: function (state, value) {
      state.isLogin = true
    }

  },
  actions: {
    getLyric: async function (context, value) {
      let res = await getMusicLyric(value)
      console.log(res);
      context.commit("updateLyricList", res.data.lrc)
    },
    getLogin: async function (context, value) {
      let res = await getPhoneLogin(value);
      // console.log(res)
      return res
    }
  },
  modules: {
  }
})
